
import java.io.*;
import javax.swing.filechooser.FileFilter;

public class FileFilterbyName extends FileFilter{ 
	String suffix; 
	public FileFilterbyName(String ext){ 
		suffix = ext; 
	} 
	public boolean accept(File file){ 
		if(file.isDirectory()){ 
			return true; 
		} 
		String fileName = file.getName(); 
		int index = fileName.lastIndexOf('.'); 
		if (index > 0 && index < fileName.length() - 1){ 
			String extension = fileName.substring(index + 1).toLowerCase();
			if (extension.equals(suffix)) 
				return true; 
		} return false; 
	}
	
	public String getDescription(){
		if(suffix.equals("p3pproj")||suffix.equals("xml")){
			if(suffix.equals("p3pproj")){
				return "P3P Policy Projects(*.p3pproj)";
			}else{
				return "XML Files(*.xml)";
			}
		}else{
		return "Files(*."+suffix+")";
		}
	}
}